﻿using System;
using System.Collections.Generic;
using System.Text;

namespace dbapi_lib.API.Util
{
    /// <summary>
    /// Class for often used data transformations, and other manipulations
    /// </summary>
    public class DataFormat
    {
        /// <summary>
        /// Default constructor.
        /// </summary>
	    private DataFormat() : base() {}

        /// <summary>
        /// Return the trueStr or the falseStr depending on the value of the Boolean object. It will return empty string if
        /// the value is null
        /// </summary>
        /// <param name="value">Boolean value</param>
        /// <param name="trueStr">return value if the boolean value is true</param>
        /// <param name="falseStr">return value if the boolean value is false</param>
        /// <returns>the trueStr or the falseStr depending on the value of the Boolean object</returns>
        public static String formatBoolean(Boolean value, String trueStr, String falseStr) {
            String ret = "";

            ret = value ? trueStr : falseStr;

            return ret;
        }

        /// <summary>
        /// Joins the given list's elements into a string separated by the given string.
        /// </summary>
        /// <param name="stringList">the list to join</param>
        /// <param name="separator">the separator string - if null or empty, a space will be used</param>
        /// <returns>the list's elements as a string - can not be null!</returns>
         public static String join(List<String> stringList, String separator) 
         {
    	    if (stringList == null || stringList.Count < 1) 
            {
    		    return "";
    	    }
    	    String sep = separator == null || separator.Length < 1 ? " " : separator;
    	    StringBuilder result = new StringBuilder();


    	    foreach (String item in stringList)
    	    {
    		    if (item == "") {
    			    continue;
    		    }
    		    if (result.Length > 0) {
    			    result.Append(sep);
    		    }
    		    result.Append(item.Trim());
    	    }
    	    return result.ToString();
        }


    }
}
